home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr01 / halcn305.zip / GSDMO_04.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-02  |  3KB  |  95 lines

  1. program GSDMO_04;
  2. {------------------------------------------------------------------------------
  3.                              DBase File Updating
  4.  
  5.        Copyright (c)  Richard F. Griffin
  6.  
  7.        20 Jaunary 1993
  8.  
  9.        102 Molded Stone Pl
  10.        Warner Robins, GA  31088
  11.  
  12.        -------------------------------------------------------------
  13.        This program demonstrates how dBase fields may be modified using
  14.        Griffin Solutions units.
  15.  
  16.        If the GSDMO_01.DBF file does not exist, the program will display a
  17.        a message that the file was not found and to run GSDMO_01 to make
  18.        the file.
  19.  
  20.        The program opens a dBase file and proceeds to list selected fields
  21.        from each record.
  22.  
  23.        It will reverse all the letters in LASTNAME and write the record
  24.        back to disk using Replace.
  25.  
  26.        Finally, it will read the file back in, list the new values, put
  27.        the old LASTNAME back to the record by reversing letters again, and
  28.        writing the record again.
  29.  
  30.        New procedures/functions introduced are:
  31.  
  32.                  Replace
  33.                  StringPut
  34.  
  35. -------------------------------------------------------------------------------}
  36.  
  37. uses
  38.    GSOBShel,
  39.    {$IFDEF WINDOWS}
  40.       WinCRT,
  41.       WinDOS;
  42.    {$ELSE}
  43.       CRT,
  44.       DOS;
  45.    {$ENDIF}
  46.  
  47. var
  48.    i       : integer;
  49.    s1,
  50.    s2      : string[30];
  51.    c       : char;
  52.  
  53. procedure WorkTheFile;            {reads the file, displays fields, and }
  54.                                   {reverses LASTNAME                    }
  55. begin
  56.    GoTop;
  57.    while not dEOF do
  58.    begin
  59.       s1 := StringGet('LASTNAME');
  60.       writeln(s1,', ', StringGet('FIRSTNAME'));
  61.  
  62.       s2 := '';                   {Reverse the LASTNAME in s2}
  63.       for i := 1 to length(s1) do s2 := s1[i] + s2;
  64.       StringPut('LASTNAME',s2);   {Store s2 in LASTNAME}
  65.       Replace;                    {Write buffer to current record}
  66.       Skip(1);
  67.    end;
  68. end;
  69.  
  70.  
  71. {------ Main Routine ------}
  72.  
  73. begin
  74.    ClrScr;
  75.    if not FileExist('GSDMO_01.DBF') then
  76.    begin
  77.       writeln('File GSDMO_01.DBF not found.  Run GSDMO_01 to create.');
  78.       halt;
  79.    end;
  80.                        {The 'Real' example starts here}
  81.  
  82.    Select(1);
  83.    Use('GSDMO_01');
  84.    WorkTheFile;
  85.    writeln('------ Now to show LASTNAME is reversed in the file:');
  86.    write('Press any Key to continue:');
  87.    c := ReadKey;
  88.    writeln;
  89.    WorkTheFile;
  90.    CloseDataBases;
  91.    writeln('------ OK, the file is back in shape now');
  92.    write('Press any Key to continue:');
  93.    c := ReadKey;
  94. end.
  95.